package ui;

import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.SWT;
import org.eclipse.wb.swt.SWTResourceManager;

public class PowerDown extends Dialog {

	protected Object result;
	protected Shell shell;
	
	private boolean bExitFlag = false;
	private Shell parent_shell;

	/**
	 * Create the dialog.
	 * @param parent
	 * @param style
	 */
	public PowerDown(Shell parent, int style) {
		super(parent, style);
		setText("Power");
		parent_shell = parent;
	}

	/**
	 * Open the dialog.
	 * @return the result
	 */
	public Object open() {
		createContents();
		shell.open();
		shell.layout();
		Display display = getParent().getDisplay();	
		Point location = parent_shell.getLocation();		// Get the location of the parent. *SR
		shell.setLocation(location.x+130, location.y+100); 	// Move popup to sit on top of main composite
		
		Label lblPoweringDown = new Label(shell, SWT.BORDER | SWT.CENTER);
		lblPoweringDown.setBackground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
		lblPoweringDown.setForeground(SWTResourceManager.getColor(SWT.COLOR_RED));
		lblPoweringDown.setFont(SWTResourceManager.getFont("Times New Roman", 20, SWT.BOLD));
		lblPoweringDown.setBounds(5, 5, 227, 45);
		lblPoweringDown.setText("Powering Down...");
		
		display.sleep();
		
		// Just sleep for 2 seconds then close the window
		try {
			Thread.sleep(2000);
		} catch (InterruptedException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
		shell.dispose(); // *SR
		return result;
	}

	/**
	 * Create contents of the dialog.
	 */
	private void createContents() {
		shell = new Shell(getParent(), getStyle());
		shell.setBackground(SWTResourceManager.getColor(SWT.COLOR_RED));
		shell.setSize(240, 55);
		shell.setText(getText());

	}

}
